package com.zr.userInfo.controller;

import com.zr.userInfo.pojo.UserInfoAddVo;
import com.zr.userInfo.service.UserInfoService;
import com.zr.util.ResultVOBuilder;
import com.zr.util.ResultVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid;


/**
 * Created by Administrator on 2019/7/3.
 */
@RestController
public class UserInfoController {

    @Autowired
    private UserInfoService userInforService;


    @GetMapping("userinfo/queryLoginId")
    public ResultVo queryLoginId(HttpServletRequest request){
        Integer loginId = (Integer) request.getSession().getAttribute("loginId");
        return userInforService.queryLoginId(loginId);
    }


    /**
     *添加
     * @param userInfoAddVo
     * @param bindingResult
     * @return
     */
    @PostMapping("essentialInformation")
    public ResultVo essentialInformation(@RequestBody @Valid UserInfoAddVo userInfoAddVo, BindingResult bindingResult){
        if (bindingResult.hasErrors()){
            return ResultVOBuilder.error(bindingResult.getFieldError().getDefaultMessage(),"500");
        }
        return userInforService.essentialInformation(userInfoAddVo
        );
    }

    /**
     * 上一页查看
     * @param id
     * @return
     */
    @GetMapping("queryByPid")
    public ResultVo queryByPid(@RequestParam("id")Integer id){

        return userInforService.queryByPid(id);
    }

}
